//
//  TabBarViewController.m
//  XIWenLeJian
//
//  Created by lanou3g on 15/11/11.
//  Copyright © 2015年 蓝足. All rights reserved.
//

#import "TabBarViewController.h"
#import "NavigationViewController.h"
#import "JokesViewController.h"
#import "MineViewController.h"
#import "VediosViewController.h"
#import "NewsViewController.h"
#import "UIView+Extension.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
// 初始化并设置子控制器
    // 新闻
    NewsViewController *newsVC = [[NewsViewController alloc]init];
    [self addChildVC:newsVC title:@"幻闻" image:@"iconfont-iconxinwen" selectedImage:@"iconfont-iconxinwen (1)"];
    
    // 段子
    JokesViewController *jokesVC = [[JokesViewController alloc]init];
    [self addChildVC:jokesVC title:@"糗段" image:@"iconfont-duanzi" selectedImage:@"iconfont-duanzi (1)"];
    
    // 视频
    VediosViewController *vediosVC = [[VediosViewController alloc]init];
    [self addChildVC:vediosVC title:@"视频" image:@"iconfont-shipin" selectedImage:@"iconfont-shipin (1)"];
    
    // 我的
    MineViewController *mineVC = [[MineViewController alloc]init];
    [self addChildVC:mineVC title:@"我" image:@"iconfont-woxuanzhong" selectedImage:@"iconfont-woxuanzhong (1)"];
    
    [[UITabBar appearance]setBarTintColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]];
}


- (void)addChildVC:(UIViewController *)childVC
             title:(NSString *)title
             image:(NSString *)image
     selectedImage:(NSString *)selectedImage;
{
    
    // 创建左上角 item
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-doubiequwei"]];
    imageView.width = 40;
    imageView.height = 40;
    childVC.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:imageView];
    
    
    
    // 设置子控制器的文字
    childVC.title = title;
    
    //设置子控制器的图片
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    
    // 设置文字样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:123 / 255.0 green:123 / 255.0 blue:123 / 255.0 alpha:1.0];
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [childVC.tabBarItem setTitleTextAttributes:textAttrs forState:(UIControlStateNormal)];
    [childVC.tabBarItem setTitleTextAttributes:selectTextAttrs forState:(UIControlStateSelected)];
    
    // 给外面传进来的小控制器包装一个导航控制器
    NavigationViewController *naVC = [[NavigationViewController alloc]initWithRootViewController:childVC];
    
    
    // 添加子控制器
    [self addChildViewController:naVC];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
